perf: replace base64.h with simdutf SIMD-accelerated codec#50
Closed
GrzywN wants to merge 1 commit into
Closed
Conversation
Closes craftzdog#42 Replace the René Nyffenegger base64.h codec with simdutf v8.2.0 (used by Node.js, Bun, Deno). Encode uses binary_to_base64 directly; decode mirrors V8's Uint8Array.fromBase64 via base64_to_binary_safe (loose, decode_up_to_bad_char=true). Behaviour changes (now TC39-compliant): - mid-string padding (e.g. SQ==QU0=) is rejected instead of silently decoded - \n in input without removeLinebreaks=true throws instead of being ignored
Contributor
Author
|
The
|
Owner
|
Amazing. Thanks! |
Closed
2 tasks
momenthana
pushed a commit
to chhezoss/react-native-quick-base64
that referenced
this pull request
Jul 21, 2026
…mentation
Replaces the René Nyffenegger header-only base64.h with simdutf v8.2.0,
the same SIMD-accelerated codec used internally by Node.js, Bun, and
Deno. Vendored as the upstream amalgamation (cpp/simdutf.{h,cpp})
keeping the zero-external-dependency setup.
- Encode (base64FromArrayBuffer) calls simdutf::binary_to_base64
directly into a pre-sized output buffer, with no intermediate
std::string copy.
- Decode (base64ToArrayBuffer) mirrors V8's Uint8Array.fromBase64
via simdutf::base64_to_binary_safe with last_chunk_handling::loose
and decode_up_to_bad_char=true. The decoded std::string is moved
into a DecodedBuffer (jsi::MutableBuffer) and returned as
jsi::ArrayBuffer(rt, shared_ptr<...>) — no memcpy.
Roundtrip throughput now matches Hermes' built-in atob/btoa on the
example app's image.json benchmark.
Behaviour changes (TC39-compliant, see Uint8Array.fromBase64 spec):
- Mid-stream padding (e.g. 'SQ==QU0=') now throws instead of
silently decoding the prefix.
- Embedded '\n' without removeLinebreaks=true now throws instead
of being silently ignored.
Test fixtures in example/src/tests/{corrupt,linebreaks}.ts updated
accordingly.
Adapted from craftzdog#50, ported onto the post-codegen QuickBase64Impl.cpp
and combined with the MutableBuffer-based no-memcpy decode path.
Closes craftzdog#50
Co-authored-by: Karol Binkowski <karolbinkowski3@proton.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #42
Replaces the René Nyffenegger
base64.hcodec with simdutf v8.2.0 — the same SIMD-accelerated base64 library used internally by Node.js, Bun, and Deno. The library is vendored as an amalgamated single-file (simdutf.h+simdutf.cpp), keeping the same zero-external-dependency setup as before.Encode (
base64FromArrayBuffer) callssimdutf::binary_to_base64directly.Decode (
base64ToArrayBuffer) mirrors V8'sUint8Array.fromBase64implementation viasimdutf::base64_to_binary_safewithlooselast-chunk handling anddecode_up_to_bad_char=true.Behaviour changes (TC39-compliant)
SQ==QU0=)[73, 65, 77]Invalid base64\nwithoutremoveLinebreaksInvalid base64\nwithremoveLinebreaks=true-_)=paddingFiles changed
cpp/simdutf.hcpp/simdutf.cppcpp/base64.hcpp/react-native-quick-base64.cppandroid/CMakeLists.txtbase64.h→simdutf.cppin sourcesexample/src/tests/corrupt.tsexample/src/tests/linebreaks.tsiOS podspec (
cpp/**/*.{h,cpp}) picks upsimdutf.h/.cppautomatically — no podspec changes needed.Screenshots